<script setup>
import { useRouter } from 'vue-router';

const props = defineProps({
  movie: {
    type: Object,
    required: true
  }
});

const router = useRouter();

const goToDetail = () => {
  router.push({ name: 'MovieDetail', params: { id: props.movie.id } });
};
</script>

<template>
  <div class="movie-card" @click="goToDetail">
    <img :src="movie.image" alt="Movie Poster" class="movie-image" />
    <h2 class="title">{{ movie.title }}</h2>
  </div>
</template>

<style scoped>
.movie-card {
  position: relative; 
  cursor: pointer;
  width: calc(50%);
  box-sizing: border-box; /* 确保宽度计算包括内边距和边框 */
}

.movie-image {
  width: 100%;
  display: block;
  height: 186px;
}

.title {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 1.2em;
  font-weight: bold;
  text-align: center;
  background: rgba(0, 0, 0, 0.2);
  padding: 8px;
  border-radius: 4px;
}
</style>